//
//  ICMusicPlayModel.m
//  DWTeacher
//
//  Created by icochu on 2022/02/22.
//  Copyright © 2022年 wlf. All rights reserved.
//

#import "ICMusicPlayModel.h"

@implementation ICMusicPlayModel
+ (BOOL)propertyIsOptional:(NSString*)propertyName {
    return YES;
}
- (BOOL)hasChinese:(NSString *)str {
    for(int i=0; i< [str length];i++){
        int a = [str characterAtIndex:i];
        if( a > 0x4e00 && a < 0x9fff)
        {
            return YES;
        }
    }
    return NO;
}
- (void)setAudio_url:(NSString *)audio_url{
    _audio_url = audio_url;
    BOOL isChaine = [self hasChinese:_audio_url];
    if (isChaine) {
        
         _audio_url = [_audio_url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    }
}
- (void)setVideo_url:(NSString *)video_url{
    _video_url = video_url;
    BOOL isChaine = [self hasChinese:video_url];
    if (isChaine) {
        
        _video_url = [video_url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    }
}
- (void)setFile:(NSString *)file{
    _file = file;
    BOOL isChaine = [self hasChinese:file];
    if (isChaine) {
        
        _file = [file stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    }
}

- (void)setStart_skip_time:(NSString *)start_skip_time{
    _start_skip_time = start_skip_time;
    float skipS = 0;
    NSArray *array = [start_skip_time componentsSeparatedByString:@":"];
    for (int i = 0; i < array.count; i++) {
        
        NSString *str = array[i];
        if (i==0) {
            skipS = str.doubleValue * 3600;
        }else if (i==1){
            skipS = skipS + str.doubleValue * 60;
        }else{
            skipS = skipS + str.doubleValue;
        }
    }
    
    self.start_skipS = skipS;
}
- (void)setEnd_skip_time:(NSString *)end_skip_time{
    _end_skip_time = end_skip_time;
    float skipS = 0;
    NSArray *array = [end_skip_time componentsSeparatedByString:@":"];
    for (int i = 0; i < array.count; i++) {
        
        NSString *str = array[i];
        if (i==0) {
            skipS = str.doubleValue * 3600;
        }else if (i==1){
            skipS = skipS + str.doubleValue * 60;
        }else{
            skipS = skipS + str.doubleValue;
        }
    }
    
    self.end_skipS = skipS;
}
- (double)audioLength{
    return self.audio_num.doubleValue - _end_skipS;
}
@end
